import { NextResponse } from "next/server"
import prisma from "@/lib/prisma"
import { getUserFromRequest } from "@/lib/auth/jwt"
import { NextRequest } from "next/server"

export async function GET(req: NextRequest) {
  try {
    // 验证用户身份
    const user = getUserFromRequest(req)
    
    if (!user) {
      return NextResponse.json(
        {
          success: false,
          error: "未授权访问",
        },
        { status: 401 }
      )
    }
    
    // 获取用户的所有配方
    const recipes = await prisma.recipe.findMany({
      where: {
        userId: user.userId
      },
      orderBy: {
        createdAt: 'desc'
      }
    })
    
    return NextResponse.json({
      success: true,
      recipes
    })
    
  } catch (error) {
    console.error("Get Cabinet API Error:", error)
    return NextResponse.json(
      {
        success: false,
        error: "获取酒柜失败",
      },
      { status: 500 }
    )
  }
} 